package tests;

import static org.junit.Assert.*;
import graphNew.DinicBasedAlgo;
import graphNew.MainGraph;
import io.IoHandler;

import java.util.Vector;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import components.Agent;
import components.Goal;
import components.Operator;
import components.Variable;

public class DinicBasedAlgoTest {

	
	MainGraph mg;
	Vector<Goal> goals;
	Vector<Variable> vars;
	Vector<Operator> operators;
	
	DinicBasedAlgo dba=null;
	
	@Before
	public void setUp() throws Exception {
		vars= new Vector<Variable>();
		goals= new Vector<Goal>();
		operators= new Vector<Operator>();
		
		try {
			IoHandler.ParseFile("input", vars, goals, operators);
		} catch (NumberFormatException e) {
			e.printStackTrace();
			fail("exception heppened");
		} catch (Exception e) {
			e.printStackTrace();
			fail("exception heppened");
		}
		mg=new MainGraph(operators);
		
		
		
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void testDinicBasedAlgo() {
		
		try {
			dba= new DinicBasedAlgo(mg, goals);
		} catch (Exception e) {
			e.printStackTrace();
			fail("exception happened");
		}
		assertNotNull(dba);
		assertTrue(dba.agentSet().size()==1);
		
	}

	@Test
	public void testRunAlgo() {
		
		try {
			dba= new DinicBasedAlgo(mg, goals);
		} catch (Exception e) {
			e.printStackTrace();
			fail("exception happened");
		}
		
		dba.setTarget(-1,2);
		
		try {
			dba.runAlgo();
		} catch (Exception e) {
			e.printStackTrace();
			fail("exception happened");
		}
		System.out.println("--------------------------");
		for (Agent i:dba.agentSet())
			System.out.println(i.getGraph().getMaingraph().vertexSet().size()+" "+i.getRank());
		try {
			IoHandler.outputToFile("dannyOutput", "input", vars, goals, operators);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

}
